package com.itboye.ihomebank.responsitory;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.ihomebank.base.BaseNetRepository;
import com.itboye.ihomebank.base.ICompleteListener;
import com.itboye.ihomebank.bean.BangDingBean;
import com.itboye.ihomebank.bean.BeiFenKeyBean;
import com.itboye.ihomebank.bean.DownBeifenBean;
import com.itboye.ihomebank.bean.HouseBean;
import com.itboye.ihomebank.bean.KaiSuoJiLu;
import com.itboye.ihomebank.bean.KeyBean;
import com.itboye.ihomebank.bean.MessWeiDuBean;
import com.itboye.ihomebank.interfaces.KeyInterface;
import com.itboye.ihomebank.net.BaseErrorListener;
import com.itboye.ihomebank.net.BaseSuccessReqListener;
import com.itboye.ihomebank.net.ByJsonRequest.Builder;

/***
 * 钥匙请求网络类
 * 
 */
public class KeyRepository extends BaseNetRepository implements
		KeyInterface<HouseBean> {

	String api = "100";

	String register = "BY_Sciener_reg";// 注册
	String addmain = "BY_Sciener_bindAdmin";// 绑定管理员
	String kaisuo = "BY_Sciener_listRecord";// 开锁记录
	String dongjie = "BY_Sciener_lockKey";// 冻结钥匙
	String jiedong = "BY_Sciener_unlockKey";// 解冻钥匙
	String shanchu = "BY_Sciener_deleteKey";// 删除钥匙
	String beifen = "BY_Sciener_backupKey";// 备份钥匙
	String jianpanPass = "BY_Sciener_resetKeyboardPwd";// 重置键盘密码
	String beifenList = "BY_Sciener_listBackup";// 备份钥匙列表
	String DeleteBeifen = "BY_Sciener_deleteBackup";// 删除备份钥匙
	String downBeifen = "BY_Sciener_downBackup";// 下载备份钥匙
	String sendJianPanPass = "BY_Sciener_getKeyboardPwd";// 发送键盘密码
	String xinxi = "BY_Repair_setlockinfo";//获取锁信息
	String yuyue = "BY_Repair_addlock";//预约装锁
	String tuisong = "BY_Sciener_ifPush";//锁推送

	String fankui = "BY_User_suggest";// 意见反馈
	String weidu = "BY_Message_count";//消息未读
	String yidu = "BY_Message_read";//消息已读

	public KeyRepository(ICompleteListener iCompleteListener) {
		super(iCompleteListener);
	}

	/**
	 * 注册
	 */
	@Override
	public void getRegister(String uid) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(register, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void getAddMain(String uid, String lock_type, String lockName,
			String lockAlias, String lockMac, String lockKey,
			String lockFlagPos, String aesKeyStr, String version) {
		Type type = new TypeToken<BangDingBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("lock_type", lock_type);
		map.put("lockName", lockName);
		map.put("lockAlias", lockAlias);
		map.put("lockMac", lockMac);
		map.put("lockKey", lockKey);
		map.put("lockFlagPos", lockFlagPos);
		map.put("aesKeyStr", aesKeyStr);
		map.put("lockVersion", version);
		(new Builder<BangDingBean>())
				.setTypeVerParamsAndReturnClass(addmain, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<BangDingBean>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 开锁记录
	 */
	@Override
	public void getKaiSuoJiLu(String uid, String lock_id, String current_page,
			String per_page) {
		Type type = new TypeToken<KaiSuoJiLu>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("lock_id", lock_id);
		map.put("current_page", current_page);
		map.put("per_page", per_page);
		(new Builder<KaiSuoJiLu>())
				.setTypeVerParamsAndReturnClass(kaisuo, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<KaiSuoJiLu>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 冻结钥匙
	 */
	@Override
	public void getDongJie(String uid, String to_uid, String lock_id,
			String key_id) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("to_uid", to_uid);
		map.put("lock_id", lock_id);
		map.put("key_id", key_id);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(dongjie, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 解冻钥匙
	 */
	@Override
	public void getJieDong(String uid, String to_uid, String lock_id,
			String key_id) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("to_uid", to_uid);
		map.put("lock_id", lock_id);
		map.put("key_id", key_id);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(jiedong, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void getShanChu(String uid, String to_uid, String lock_id,
			String key_id) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("to_uid", to_uid);
		map.put("lock_id", lock_id);
		map.put("key_id", key_id);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(shanchu, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void getBeiFei(String uid, String lock_Id, String key_id,
			String admin_ps, String nokey_ps, String delete_ps) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("lock_id", lock_Id);
		map.put("key_id", key_id);
		map.put("admin_ps", admin_ps);
		map.put("nokey_ps", nokey_ps);
		map.put("delete_ps", delete_ps);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(beifen, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 重置键盘密码
	 */
	@Override
	public void getJianPanPass(String uid, String lock_id, String pwd_info,
			String timestamp) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("lock_id", lock_id);
		map.put("pwd_info", pwd_info);
		map.put("timestamp", timestamp);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(jianpanPass, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 备份钥匙列表
	 */
	@Override
	public void getBeifeiList(String uid) {
		Type type = new TypeToken<List<BeiFenKeyBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		(new Builder<List<BeiFenKeyBean>>())
				.setTypeVerParamsAndReturnClass(beifenList, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<List<BeiFenKeyBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 删除备份钥匙
	 */
	@Override
	public void getDeleteBeiFen(String uid, String lock_id, String key_id) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("lock_id", lock_id);
		map.put("key_id", key_id);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(DeleteBeifen, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 下载备份钥匙
	 */
	@Override
	public void getDownKeyBeiFen(String uid, String lock_id, String key_id) {
		Type type = new TypeToken<DownBeifenBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("lock_id", lock_id);
		map.put("key_id", key_id);
		(new Builder<DownBeifenBean>())
				.setTypeVerParamsAndReturnClass(downBeifen, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<DownBeifenBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 发送键盘密码
	 */
	@Override
	public void getKeyboardPwd(String uid, String lock_id, String pwd_type,
			String to_phone, String start, String end) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("lock_id", lock_id);
		map.put("pwd_type", pwd_type);
		map.put("to_phone", to_phone);
		map.put("start", start);
		map.put("end", end);

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(sendJianPanPass, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 意见反馈
	 */
	@Override
	public void getFankui(String uid, String content) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("content", content);

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(fankui, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}
	/**
	 * 获取锁信息
	 */
	@Override
	public void getSuoXinXi() {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(xinxi, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
		
	}
	/**
	 * 预约装锁
	 */
	@Override	
	public void getYuYue(String uid, String name, String mobile, String address) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("name", name);
		map.put("mobile", mobile);
		map.put("address", address);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(yuyue, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
		
	}
	/**
	 * 锁推送
	 */
	@Override
	public void getTuiSong(String uid, String lock_id, String push) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("lock_id", lock_id);
		map.put("push", push);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(tuisong, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
		
	}
	/**
	 * 消息未读
	 */
	@Override
	public void getWeiDu(String uid) {
		Type type = new TypeToken<MessWeiDuBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		(new Builder<MessWeiDuBean>())
				.setTypeVerParamsAndReturnClass(weidu, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<MessWeiDuBean>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
		
	}
	/**
	 * 消息已读
	 */
	@Override
	public void getYiDu(String uid, String id) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("id", id);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(yidu, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

}
